package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.HelpContent;
import com.zygh.policeasset.pojo.Role;
import com.zygh.policeasset.service.HelpContentService;
import com.zygh.policeasset.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping({"/helpContent"})
@Api(tags = {"帮助模块"})
@RestController
public class HelpContentController {
    @Autowired
    HelpContentService helpContentService;

    @RequestMapping(value = {"/findAll"}, method = {RequestMethod.GET})
    @ApiOperation("分页查询所有")
    public Object findAll(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                          @RequestParam(defaultValue = "10", value = "pageSize") int pageSize,
                          @RequestParam(value = "title", required = false) String title) {
        return helpContentService.findAll(pageNum, pageSize, title);
    }

    @RequestMapping(value = {"/findAllByTitle"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有")
    public Object findAllRole(String title) {
        return helpContentService.findAllByTitle(title);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object addRole(@RequestBody HelpContent helpContent) {
        if (helpContentService.add(helpContent).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object updateRole(@RequestBody HelpContent helpContent) {
        if (helpContentService.update(helpContent) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改错误");
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("删除")
    public Object delete(@PathVariable Integer id) {
        if (helpContentService.delete(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }

    @GetMapping({"/findById"})
    @ApiOperation("根据id查询")
    public Object findById(Integer id) {
        return new CommonResult().success(helpContentService.findById(id));
    }
}